<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
if (!defined("Wager_lib_include")){
	define("Wager_lib_include", 1);
	include_once(__Modules_Path."/Gamble.lib.php");
	include_once(__Modules_Path."/Odds.lib.php");
	include_once(__Common_Path."/SysParam.inc.php");

/**
 * 取得陣列資料
 * @param	intLID 樂透序號
 * @param	intLType 樂透種類序號
 * @param	intGID 操盤序號
 * @param	intBT 下注種類
 * @param	intNum 號碼
 * @param	strChoiceNum 選擇次號碼
 * @return	 Array[?x] = ?y，?x -> 欄位名稱，?y -> 欄位值
 */
	function getTodayGameArrayData($intLID, $intLType, $intGID, $intBT, $intNum, $strChoiceNum = ""){
		global $_Conn, $$_Conn;
		$arrTmp = array();
		@include(__Common_Path."/Emergency.inc.php");
		if($_isStopAllBet == 1)return false;

		$arrGamble = getNewGambleData($intLID, 0);
		if($arrGamble === false || sizeof($arrGamble) == 0 || $arrGamble["ID"] != $intGID)return false;

		while(list($k, $v) = each($arrGamble)){
			if($k == "ID")$k = "GambleID";
			$arrTmp[$k] = $v;
		}
		
		$strNum = (string)$intNum;
		$strBT = (string)$intBT;
		$intLimit = 1;
		if($intLType == 1 && ($intBT == 1 || $intBT == 28)){
			$intLimit = 2;
			$strBT = "1, 28";
		}elseif(($intLType == 1 && ($intBT >= 31 && $intBT <= 43)) || ($intLType == 2 && ($intBT >= 69 && $intBT <= 77))){
			$intLimit = 1;
			$strNum = $strChoiceNum;
		}
		$strSQL = "select * from `bet_TodayGame".$intLID."` where GambleID = '".$intGID."' and LottoID = '".$intLID."' and Bet_Type in (".$strBT.") and Number in (".$strNum.") order by Odds asc, Number limit 0,".$intLimit;

		//print "\n\n".$strSQL."\n\n";
		if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
			$GLOBALS["errorhidden"] = "Find Data Error!";
			$GLOBALS["errorhidden"] = "SQL: ".$strSQL.", \nError: ".mysql_error($$_Conn).", \nLine: ".__LINE__.", \nPage: ".__FILE__;
			return false;
		}
		
		if(PMA_mysql_num_rows($RS) < $intLimit){
			$GLOBALS["errorhidden"] = "Can not Find Data!!";
			$GLOBALS["errorhidden"] = "SQL: ".$strSQL.", \nError: ".mysql_error($$_Conn).", \nLine: ".__LINE__.", \nPage: ".__FILE__;
			return false;
		}
		
		while($Rows = PMA_mysql_fetch_array($RS, MYSQL_ASSOC)){
			while(list($k, $v) = each($Rows)){
				if(preg_match("/^tol/", $k)){
					$arrTmp[$k] += round($v, 5);
				}elseif($k == "Bet_Type"){
					$arrTmp[$k] = $intBT;
				}elseif($Rows["Bet_Type"] == $intBT){
					$arrTmp[$k] = $v;
				}
			}
		}
		return $arrTmp;
	}

/**
 * 取得多筆陣列資料
 * @param	intLID 樂透序號
 * @param	intLType 樂透種類序號
 * @param	intGID 操盤序號
 * @param	intBT 下注種類
 * @param	arrNum 號碼陣列
 * @param	strChoiceNum 選擇次號碼
 * @return	 Array[?x] = ?y，?x -> 欄位名稱，?y -> 欄位值
 */
	function getMultiTodayGameArrayData($intLID, $intLType, $intGID, $intBT, $arrNum){
		global $_Conn, $$_Conn;
		$arrTmp = array();
		@include(__Common_Path."/Emergency.inc.php");
		if($_isStopAllBet == 1)return false;

		$arrGamble = getNewGambleData($intLID, 0);
		if($arrGamble === false || sizeof($arrGamble) == 0 || $arrGamble["ID"] != $intGID)return false;

		while(list($k, $v) = each($arrGamble)){
			if($k == "ID")$k = "GambleID";
			$arrGamble[$k] = $v;
		}
		
		$strBT = (string)$intBT;
		if($intLType == 1 && ($intBT == 1 || $intBT == 28)){
			$strBT = "1, 28";
		}
		$strNum = implode(",", $arrNum);

		$strSQL = "select * from `bet_TodayGame".$intLID."` where GambleID = '".$intGID."' and LottoID = '".$intLID."' and Bet_Type in (".$strBT.") and Number in (".$strNum.") order by Bet_Type asc, Number ";

		//print "\n\n".$strSQL."\n\n";
		if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
			$GLOBALS["errorhidden"] = "Find Data Error!";
			$GLOBALS["errorhidden"] = "SQL: ".$strSQL.", \nError: ".mysql_error($$_Conn).", \nLine: ".__LINE__.", \nPage: ".__FILE__;
			return false;
		}
		
		if(PMA_mysql_num_rows($RS) == 0){
			$GLOBALS["errorhidden"] = "Can not Find Data!!";
			$GLOBALS["errorhidden"] = "SQL: ".$strSQL.", \nError: ".mysql_error($$_Conn).", \nLine: ".__LINE__.", \nPage: ".__FILE__;
			return false;
		}
		
		$arrTmp = array();
		while($Rows = PMA_mysql_fetch_array($RS, MYSQL_ASSOC)){
			if($Rows['isStopBet'] == 1){
				$arrGamble['isStopBet'] = 1;
				return array("GData" => $arrGamble);
			}

			while(list($k, $v) = each($Rows)){
				if(preg_match("/^tol/", $k)){
					$arrTmp[$Rows['Number']][$k] += round($v, 5);
				}elseif($k == "Bet_Type"){
					$arrTmp[$Rows['Number']][$k] = $intBT;
				}elseif($Rows["Bet_Type"] == $intBT){
					$arrTmp[$Rows['Number']][$k] = $v;
				}
			}
		}
		return array("GData" => $arrGamble, "NData" => $arrTmp);
	}


/**
取得賠率資料
 * @param	intLID 樂透種類序號
 * @param	intGID 操盤序號
 * @param	intBT 下注種類
 * @param	intNum 號碼
 * @param	intOID 賠率序號
 * @return	 fload -> 成功，false -> 失敗
*/
	function getNewOddsFromDB($intLID, $intGID, $intBT, $intNum, $intOID){
		global $_Conn, $$_Conn;

		$strSQL = "select Odds from `bet_Odds` where ID = ".$intOID." and GambleID = ".$intGID." and LottoID = ".$intLID." and Bet_Type = ".$intBT." and Number = ".$intNum;
		//print $strSQL;
		if(!$RS = @PMA_mysql_query($strSQL, $$_Conn))return false;
		if(PMA_mysql_num_rows($RS) == 0)return false;
		$Rows = PMA_mysql_fetch_object($RS);
		return $Rows -> Odds;
	}

/**
 * 取得下注資料
 * @param	intLID 樂透序號
 * @param	intLType 樂透種類序號
 * @param	intGID 操盤序號
 * @param	intBT 下注種類
 * @param	intNum 號碼
 * @param	intOID 賠率序號
 * @return	 Array[?x] = ?y，?x -> 欄位名稱，?y -> 欄位值
 */
	function getWagerArrayData($intLID, $intLType, $intGID, $intBT, $intNum, $intOID, $flOdds, $strChoiceNum = ""){
		$arrOData = array();
		$arrOData["isError"] = false;
		$arrOData["isMessage"] = false;

		//沒有此賽程資料
		if(!$arrOData = getTodayGameArrayData($intLID, $intLType, $intGID, $intBT, $intNum, $strChoiceNum)){
			$arrOData["isError"] = true;
			$arrOData["Err_Message"] = "NoLottoData";
			return $arrOData;
		}

		//是否停押
		if($arrOData["isStopBet"] == "1"){
			$arrOData["isError"] = true;
			$arrOData["Err_Message"] = "StopWager";
			return $arrOData;
		}

		//是否超過截止下注時間
		if(isOverWgaerTime($intLID, $intLType, $intBT, $arrOData["GameDate"], $arrOData["GameTime"], $arrOData["EndGameTime"])){
			$arrOData["isError"] = true;
			$arrOData["Err_Message"] = "GameEnd";
			//print "QQQ";
			return $arrOData;
		}

		//當組  3 or 6 轉直時，原指定號碼，和選出來最小賠率號碼不同時
		if((($intLType == 1 && $intBT >= 31 && $intBT <= 43) || ($intLType == 2 && $intBT >= 69 && $intBT <= 77)) && $intNum != $arrOData["Number"]){
			$arrOData["isMessage"] = true;
			$arrOData["Message"] = "OddsChange";
		//輸入賠率序號小於取得系統最新的賠率序號，比對其賠率，若輸入賠率序號之賠率小於系統取得最新賠率，則採用輸入賠率序號及賠率
		}elseif($intOID < $arrOData["OddsID"]){
			if($flOdds = getNewOddsFromDB($intLID, $intGID, $intBT, $intNum, $intOID)){
				if($arrOData["Odds"] > $flOdds){
					$arrOData["OddsID"] = $intOID;
					$arrOData["Odds"] = $flOdds;
				}else{
					$arrOData["isMessage"] = true;
					$arrOData["Message"] = "OddsChange";
				}
			}
		//輸入賠率序號大於取得系統最新的賠率序號，顯示賠率已更改
		}elseif($intOID > $arrOData["OddsID"]){
			$arrOData["isMessage"] = true;
			$arrOData["Message"] = "OddsChange";
		}
		$arrOData["LType"] = $intLType;
		return  $arrOData;
	}


/**
 * 取得下注資料
 * @param	intLID 樂透序號
 * @param	intLType 樂透種類序號
 * @param	intGID 操盤序號
 * @param	intBT 下注種類
 * @param	arrNum 號碼陣列
 * @param	arrOID 賠率序號
 * @return	 Array[?x] = ?y，?x -> 欄位名稱，?y -> 欄位值
 */
	function getMultiWagerArrayData($intLID, $intLType, $intGID, $intBT, $arrNum, $arrOID){
		$arrOData = array();
		$arrOData["isError"] = false;
		$arrOData["isMessage"] = false;

		//沒有此賽程資料
		if(!$arrOData = getMultiTodayGameArrayData($intLID, $intLType, $intGID, $intBT, $arrNum)){
			$arrOData["isError"] = true;
			$arrOData["Err_Message"] = "NoLottoData";
			return $arrOData;
		}

		//是否停押
		if($arrOData["GData"]["isStopBet"] == "1"){
			$arrOData["isError"] = true;
			$arrOData["Err_Message"] = "StopWager";
			return $arrOData;
		}

		//是否超過截止下注時間
		if(isOverWgaerTime($intLID, $intLType, $intBT, $arrOData["GData"]["GameDate"], $arrOData["GData"]["GameTime"], $arrOData["GData"]["EndGameTime"])){
			$arrOData["isError"] = true;
			$arrOData["Err_Message"] = "GameEnd";
			//print "QQQ";
			return $arrOData;
		}

		//輸入賠率序號不等於取得系統最新的賠率序號
		foreach($arrOData["NData"] as $intNum => $arrOD){
			if($arrOID[$intNum] != $arrOD["OddsID"]){
				$arrOData["isMessage"] = true;
				$arrOData["Message"] = "OddsChange";
			}
		}
		$arrOData["GData"]["LType"] = $intLType;
		return  $arrOData;
	}

/**
 * 是否超過截止下注時間
 * @param	intLID 樂透序號
 * @param	intLType 樂透種類序號
 * @param	intBT 下注種類序號
 * @param	strGDate 開獎日期
 * @param	strGTime 開獎時間
 * @param	strEGTime 截止下注時間
 * @return	boolean
 */
	function isOverWgaerTime($intLID, $intLType, $intBT, $strGDate, $strGTime, $strEGTime){
		$arrGDate = explode("-", $strGDate);
		$arrGTime = explode(":", $strGTime);

		$isSN = false;
		if($intLType == 1){
			switch($intBT){
				case 1:
				case 2:
				case 3:
				case 16:
				case 28: //特碼 46
					//$strEndGameTime = $arrOData["EndGameTimeSN"];
					$isSN = true;
					$strEGTime = ($arrGTime[1] > 25)?$arrGTime[0].":37:00":$arrGTime[0].":07:00";
					break;
			}
		}
		//若 3D or 3T 的停止下注時間大於 08:30:00 (美東)，則以 08:30:00 為主
		if(($intLID == 2 || $intLID == 3) && $strGDate == date("Y-m-d") && $strEGTime > "08:30:00"){
			$strEGTime ="08:30:00"; 
			$isSN = true;
		}

		//$strEGTime = ($intBT == 1)?$arrOData["EndGameTimeSN"]:$arrOData["EndGameTime"];
		$arrEGTime = explode(":", $strEGTime);
		$intGTime = mktime($arrGTime[0], $arrGTime[1], $arrGTime[2], $arrGDate[1], $arrGDate[2], $arrGDate[0]);
		$intEGTime = mktime($arrEGTime[0], $arrEGTime[1], $arrEGTime[2], $arrGDate[1], $arrGDate[2], $arrGDate[0]);

		if($intEGTime > $intGTime && $arrGTime[0] < 12 && $arrEGTime[0] > 12){ //若是跨 server 23:59 ~ 00:00
			$intEGTime -= 86400;
		}
		if($isSN == false && $intEGTime > $intGTime)$intEGTime = $intGTime;

		if($intEGTime <= time()){
			//print time()."==".$intEGTime."<br />";
			//print date("Y-m-d H:i:s", time())."==".date("Y-m-d H:i:s", $intEGTime)."<br />";
			return true;
		}
		return false;
	}

/**
 * 取得賠率資料
 * @param	intLType 樂透種類序號
 * @param	intBT 下注種類
 * @param	intNum 號碼
 * @param	flOdds 賠率值
 * @param	intGNo 樂透期數
 * @param	flOdds_second 第二組賠率值
 * @param	arrJoinNumber 連碼號碼組 (Array)
 * @param	intJoinNo 連碼號碼組可產生之組數
 * @return	 String
 */
	function getWagerConditions($intLType, $intBT, $intNum, $flOdds, $intGNo, $flOdds_second = null, $arrJoinNumber = null, $intJoinNo = 0, $arrJNumOdds = null){
		switch($intLType){
			case 1:
				return getWagerConditionsFor6L($intLType, $intBT, $intNum, $flOdds, $intGNo, $flOdds_second, $arrJoinNumber, $intJoinNo, $arrJNumOdds);
				break;

			case 2:
				return getWagerConditionsFor3D($intLType, $intBT, $intNum, $flOdds, $intGNo, $flOdds_second, $arrJoinNumber, $intJoinNo);
				break;

			case 3:
				return getWagerConditionsFor7Star($intLType, $intBT, $intNum, $flOdds, $intGNo, $flOdds_second, $arrJoinNumber, $intJoinNo);
				break; 

			case 4:
				return getWagerConditionsFor10M($intLType, $intBT, $intNum, $flOdds, $intGNo, $flOdds_second, $arrJoinNumber, $intJoinNo, $arrJNumOdds);
				break;
		}
		return "";
	}

/**
 * 組合 7Star 下注內容資料 
 * @param	intLType 樂透種類序號
 * @param	intLID 樂透序號
 * @param	intBT 下注種類
 * @param	intNum 號碼
 * @return	 String
 */
	function getWagerConditionsForError($intLType, $intLID, $intBT, $intNum){
		$strCon = getWagerConditions($intLType, $intBT, $intNum, 0, 0, null, null, 0);
		preg_match("/<!--BTTip@bof\/\/-->(.+)<!--BTTip@eof\/\/-->/s", $strCon, $arrCon);
		return WagerFormTrans($intLID, $intBT, $arrCon[1]);
	}

/**
 * 組合 六合彩 下注內容資料 
 * @param	intLType 樂透種類序號
 * @param	intBT 下注種類
 * @param	intNum 號碼
 * @param	flOdds 賠率值
 * @param	intGNo 樂透期數
 * @param	flOdds_second 第二組賠率值
 * @param	arrJoinNumber 連碼號碼組 (Array)
 * @param	intJoinNo 連碼號碼組可產生之組數
 * @return	 String
 */
	function getWagerConditionsFor6L($intLType, $intBT, $intNum, $flOdds, $intGNo, $flOdds_second, $arrJoinNumber, $intJoinNo, $arrJNumOdds){
		$strNum = (string)$intNum;
		$strJoinNumber	= null;
		$strOddsTip = "";
		$intCNum30 = $intNum;

		if (is_array($arrJoinNumber)) {
			foreach ($arrJoinNumber as $strJN) {
				if($intNum == 0){
					if($intBT == 30){
						$intJN = (int)$strJN;
						if($intJN > 12){
							$intJN -= 12;
							$intCNum30 = 1;
						}
						$strJoinNumber .= '{Show-Animals'.($intJN).'-Name}.';
					}elseif($intBT >= 32 && $intBT <= 37){
						$strJoinNumber .= '{Show-Animals'.((int)$strJN).'-Name}.';
					}elseif($intBT >= 38 && $intBT <= 43){
						$strJoinNumber .= '{Show-Mantissa'.((int)$strJN).'-Name}.';
					}else{
						$strJoinNumber .= $strJN .'.';
					}
				}else{
					if($intBT >= 32 && $intBT <= 37){
						$arrJN = explode(",", $strJN);
						foreach ($arrJN as $k => $v) {
							$arrJN[$k] = '{Show-Animals'.((int)$v).'-Name}';
						}
						$strJoinNumber .= '['.implode(",", $arrJN).']x';
					}elseif($intBT >= 38 && $intBT <= 43){
						$arrJN = explode(",", $strJN);
						foreach ($arrJN as $k => $v) {
							$arrJN[$k] = '{Show-Mantissa'.((int)$v).'-Name}';
						}
						$strJoinNumber .= '['.implode(",", $arrJN).']x';
					}else{
						$strJoinNumber .= '['.$strJN .']x';
					}
				}

				if($intBT >= 30 && $intBT <= 43){
					$arrOddsTip = array();
					foreach ($arrJNumOdds as $intJN => $strOdds){
						if($intBT == 30){
							if($intJN > 12)$intJN -= 12;
							$arrOddsTip[] = ' {Show-Animals'.((int)$intJN).'-Name} (<span class="wager_color_red">'.$strOdds.'</span>)';
						}elseif($intBT >= 32 && $intBT <= 37){
							$arrOddsTip[] = ' {Show-Animals'.((int)$intJN).'-Name} (<span class="wager_color_red">'.$strOdds.'</span>)';
						}elseif($intBT >= 38 && $intBT <= 43){
							$arrOddsTip[] = ' {Show-Mantissa'.((int)$intJN).'-Name} (<span class="wager_color_red">'.$strOdds.'</span>)';
						}else{
							$arrOddsTip[] = sprintf("%02s", $intJN) .'(<span class="wager_color_red">'.$strOdds.'</span>)';
						}
					}
					$strOddsTip = implode(", ", $arrOddsTip);
				}
			}
			$strJoinNumber = substr($strJoinNumber, 0, -1);
		}

		switch($intBT){
			case 1:
			case 28: //特碼 46
			case 4:
			case 21:
			case 22:
			case 23:
			case 24:
			case 25:
			case 26:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 2:
			case 5:
				$strNum = ($intNum == 0) ? "{Show-Odd-Name}":"{Show-Even-Name}";
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 3:
			case 6:
				$strNum = ($intNum == 0) ? "{Show-Over-Name}":"{Show-Under-Name}";
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 7:
			case 9:
			case 11:
				$strNum = '{Show-Bet_Type'. $intBT .'-Name}';
				break;

			case 8:
				$strNum 	= '{Show-WinTwo-Name}';
				$strNum_second	= '{Show-WinThree-Name}';
				break;

			case 10:
				$strNum 	= '{Show-WinSpecial-Name}';
				$strNum_second	= '{Show-WinTwo-Name}';
				break;

			case 12:
				$intNormalNumSerie = floor($intNum / 10);
				$intNum = $intNum % 10;
				$strNum = ($intNum == 0) ? "{Show-Odd-Name}":"{Show-Even-Name}";
				$strBetTypeTip = "{Show-NormalNo".$intNormalNumSerie."-Name} -- ".$strNum;
				break;

			case 13:
				$intNormalNumSerie = floor($intNum / 10);
				$intNum = $intNum % 10;
				$strNum = ($intNum == 0) ? "{Show-Over-Name}":"{Show-Under-Name}";
				$strBetTypeTip = "{Show-NormalNo".$intNormalNumSerie."-Name} -- ".$strNum;
				break;

			case 14:
				$intNormalNumSerie = floor($intNum / 10);
				$intNum = $intNum % 10;
				$strBetTypeTip = "{Show-NormalNo".$intNormalNumSerie."-Name} -- {Show-Color".(string)$intNum."-Name}";
				break;

			case 16:
				$strNum = ($intNum == 0) ? "{Show-SOdd-Name}":"{Show-SEven-Name}";
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 17:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- {Show-Color".(string)$intNum."-Name}";
				break;

			case 18:
			case 19:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- {Show-Animals".(string)$intNum."-Name}";
				break;

			case 20:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- {Show-Mantissa".(string)$intNum."-Name}";
				break;

			case 27:
				$intNormalNumSerie = floor($intNum / 10);
				$intNum = $intNum % 10;
				$strNum = ($intNum == 0) ? "{Show-SOdd-Name}":"{Show-SEven-Name}";
				$strBetTypeTip = "{Show-NormalNo".$intNormalNumSerie."-Name} -- ".$strNum;
				break;

			case 29:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- {Show-HelfColor".(string)$intNum."-Name}";
				break;

			case 30:
				$strNum = "{Show-Bet_Type".$intBT."-Name} -- {Show-SA".(string)$intCNum30."-Name}";
				break;

			default:
				$strNum = '{Show-Bet_Type'. $intBT .'-Name}';
				break;
		}

		if ($intBT == 7 || $intBT == 9 || $intBT == 11) {
			if($intJoinNo > 1)$strTmp = '<br />{Show-MultiItems-Name}[&nbsp;<span class="wager_joinno_color">'.$intJoinNo.'</span>&nbsp;]&nbsp;{Show-Items-Name}';
			return '<span class="wager_color_blue"><!--Lotto//--> {Show-GameNo-Name} <b>'. sprintf("%03s", $intGNo) .'</b></span><br /><span class="wager_color_red">{Show-JoinNumber-Name} --&nbsp;'. $strNum .'</span>@<span class="wager_color_red">'. $flOdds .'</span>'.$strTmp.'<br /><span class="wager_join_color">'.$strJoinNumber.'</span>';
		} elseif ($intBT == 8 || $intBT == 10) {
			if($intJoinNo > 1)$strTmp = '<br />{Show-MultiItems-Name}[&nbsp;<span class="wager_joinno_color">'.$intJoinNo.'</span>&nbsp;]&nbsp;{Show-Items-Name}';
			return '<span class="wager_color_blue"><!--Lotto//--> {Show-GameNo-Name} <b>'. sprintf("%03s", $intGNo) .'</b></span><br /><span class="wager_color_red">{Show-JoinNumber-Name} --&nbsp;'. $strNum .'</span>@<span class="wager_color_red">'. $flOdds .'</span><span class="wager_color_red">&nbsp;,&nbsp;'. $strNum_second .'</span>@<span class="wager_color_red">'. $flOdds_second .'</span>'.$strTmp.'<br /><span class="wager_join_color">'.$strJoinNumber.'</span>';
		}elseif ($intBT >= 30 && $intBT <= 50) {
			if($intJoinNo > 1)$strTmp = '<br />{Show-MultiItems-Name}[&nbsp;<span class="wager_joinno_color">'.$intJoinNo.'</span>&nbsp;]&nbsp;{Show-Items-Name}';
			return '<span class="wager_color_blue"><!--Lotto//--> {Show-GameNo-Name} <b>'. sprintf("%03s", $intGNo) .'</b></span><br /><span class="wager_color_red">'. $strNum .'</span>@ '. $strOddsTip .$strTmp.'<br /><span class="wager_join_color">'.$strJoinNumber.'</span>';
		} else {
			return "<span class=\"wager_color_blue\"><!--Lotto//--> {Show-GameNo-Name} <b>".sprintf("%03s", $intGNo)."</b></span><br /><!--BTTip@bof//--><span class=\"wager_color_red\">".$strBetTypeTip."</span><!--BTTip@eof//-->@<span class=\"wager_color_red\">".$flOdds."</span>";
		}
	}


/**
 * 組合 3D 下注內容資料 
 * @param	intLType 樂透種類序號
 * @param	intBT 下注種類
 * @param	intNum 號碼
 * @param	flOdds 賠率值
 * @param	intGNo 樂透期數
 * @param	flOdds_second 第二組賠率值
 * @param	arrJoinNumber 連碼號碼組 (Array)
 * @param	intJoinNo 連碼號碼組可產生之組數
 * @return	 String
 */
	function getWagerConditionsFor3D($intLType, $intBT, $intNum, $flOdds, $intGNo, $flOdds_second, $arrJoinNumber, $intJoinNo){
		$strNum = (string)$intNum;
		$strJoinNumber	= null;
		//print_r($arrJoinNumber);
		if (is_array($arrJoinNumber)) {
			if($intBT >= 78 && $intBT <= 83){
				foreach ($arrJoinNumber as $arrJN) {
					$strJoinNumber .= ' '.join("", $arrJN).' x';
				}
				$strJoinNumber = substr($strJoinNumber, 0, -1);

			}else{
				foreach ($arrJoinNumber as $intJN) {
					$strJoinNumber .= $intJN .'.';
				}
				$strJoinNumber = substr($strJoinNumber, 0, -1);
			}
		}

		switch($intBT){
			case 51:
			case 54:
			case 57:
			case 60:
			case 90:
			case 91:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 64:
			case 65:
			case 66:
			case 67:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".sprintf("%02s", $strNum);
				break;

			case 92:
			case 93:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".sprintf("%03s", $intNum);
				break;

			case 61:
				if((int)$strNum == 6){
					$strNum = "0~6";
				}elseif((int)$strNum == 21){
					$strNum = "21~27";
				}
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 52:
			case 55:
			case 58:
			case 62:
				$strNum = ($intNum == 0) ? "{Show-Odd-Name}":"{Show-Even-Name}";
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 53:
			case 56:
			case 59:
			case 63:
				$strNum = ($intNum == 0) ? "{Show-Over-Name}":"{Show-Under-Name}";
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 84:
			case 85:
			case 86:
				$strNum = ($intNum == 0) ? "{Show-Prime-Name}":"{Show-Composite-Name}";
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 69:
			case 70:
			case 71:
			case 72:
			case 73:
			case 74:
			case 75:
			case 76:
			case 77:
			case 78:
			case 79:
			case 80:
			case 81:
			case 82:
			case 83:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- (".$strJoinNumber.")";
				break;

			case 68:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} ";
				break;

			case 87:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- {Show-OEParlay".(string)$intNum."-Name}";
				break;

			case 88:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- {Show-OUParlay".(string)$intNum."-Name}";
				break;

			case 89:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- {Show-PCParlay".(string)$intNum."-Name}";
				break;
		}

		return "<span class=\"wager_color_blue\"><!--Lotto//--> {Show-GameNo-Name} <b>".sprintf("%03s", $intGNo)."</b></span><br /><!--BTTip@bof//--><span class=\"wager_color_red\">".$strBetTypeTip."</span><!--BTTip@eof//-->@<span class=\"wager_color_red\">".$flOdds."</span>";
	}


/**
 * 組合 7Star 下注內容資料 
 * @param	intLType 樂透種類序號
 * @param	intBT 下注種類
 * @param	intNum 號碼
 * @param	flOdds 賠率值
 * @param	intGNo 樂透期數
 * @param	flOdds_second 第二組賠率值
 * @param	arrJoinNumber 連碼號碼組 (Array)
 * @param	intJoinNo 連碼號碼組可產生之組數
 * @return	 String
 */
	function getWagerConditionsFor7Star($intLType, $intBT, $intNum, $flOdds, $intGNo, $flOdds_second, $arrJoinNumber, $intJoinNo){
		$strNum = (string)$intNum;
		$strJoinNumber	= null;
		//print_r($arrJoinNumber);
		if (is_array($arrJoinNumber)) {
			foreach ($arrJoinNumber as $intJN) {
				$strJoinNumber .= $intJN .'.';
			}
			$strJoinNumber = substr($strJoinNumber, 0, -1);
		}

		switch($intBT){
			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
			case 6:
				$intLNum = floor((int)$strNum / 10);
				$intRNum = (int)$strNum % 10;
				$arrTmp = array("", "%s%sxx", "%sx%sx", "%sxx%s", "x%s%sx", "x%sx%s", "xx%s%s");
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name}-- ".sprintf($arrTmp[$intBT], $intLNum, $intRNum);
				break;

			case 7:
			case 8:
			case 9:
			case 10:
				$intLNum = floor((int)$strNum / 100);
				$intMNum = floor((int)$strNum / 10) % 10;
				$intRNum = (int)$strNum % 10;
				$arrTmp = array(7 => "%s%s%sx", 8 => "%s%sx%s", 9 => "%sx%s%s", 10 =>"x%s%s%s");
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".sprintf($arrTmp[$intBT], $intLNum, $intMNum, $intRNum);
				break;

			case 13:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".sprintf("%03s", $strNum);
				break;

			case 11:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".sprintf("%04s", $strNum);
				break;

			case 12:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".sprintf("%02s", $strNum);
				break;

			case 14:
				$arrTmp = array(0 => "OXXX {Show-Odd-Name}", 1 => "OXXX {Show-Even-Name}", 
								10 => "XOXX {Show-Odd-Name}", 11 => "XOXX {Show-Even-Name}", 
								20 => "XXOX {Show-Odd-Name}", 21 => "XXOX {Show-Even-Name}", 
								30 => "XXXO {Show-Odd-Name}", 31 => "XXXO {Show-Even-Name}");

				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$arrTmp[$intNum];
				break;

			case 15:
				$arrTmp = array(0 => "OXXX {Show-Over-Name}", 1 => "OXXX {Show-Under-Name}", 
								10 => "XOXX {Show-Over-Name}", 11 => "XOXX {Show-Under-Name}", 
								20 => "XXOX {Show-Over-Name}", 21 => "XXOX {Show-Under-Name}", 
								30 => "XXXO {Show-Over-Name}", 31 => "XXXO {Show-Under-Name}");

				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$arrTmp[$intNum];
				break;

			case 16:
				$arrTmp = array(0 => "OOXX {Show-Odd-Name}", 1 => "OOXX {Show-Even-Name}", 
								10 => "OXOX {Show-Odd-Name}", 11 => "OXOX {Show-Even-Name}", 
								20 => "OXXO {Show-Odd-Name}", 21 => "OXXO {Show-Even-Name}", 
								30 => "XOOX {Show-Odd-Name}", 31 => "XOOX {Show-Even-Name}",
								40 => "XOXO {Show-Odd-Name}", 41 => "XOXO {Show-Even-Name}",
								50 => "XXOO {Show-Odd-Name}", 51 => "XXOO {Show-Even-Name}"
								);

				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$arrTmp[$intNum];
				break;

			case 17:
				$arrTmp = array(0 => "OOXX {Show-Over-Name}", 1 => "OOXX {Show-Under-Name}", 
								10 => "OXOX {Show-Over-Name}", 11 => "OXOX {Show-Under-Name}", 
								20 => "OXXO {Show-Over-Name}", 21 => "OXXO {Show-Under-Name}", 
								30 => "XOOX {Show-Over-Name}", 31 => "XOOX {Show-Under-Name}",
								40 => "XOXO {Show-Over-Name}", 41 => "XOXO {Show-Under-Name}",
								50 => "XXOO {Show-Over-Name}", 51 => "XXOO {Show-Under-Name}"
								);

				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$arrTmp[$intNum];
				break;

			case 18:
			case 19:
			case 20:
			case 21:
			case 22:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;
		}

		return "<span class=\"wager_color_blue\"><!--Lotto//--> {Show-GameNo-Name} <b>".sprintf("%03s", $intGNo)."</b></span><br /><!--BTTip@bof//--><span class=\"wager_color_red\">".$strBetTypeTip."</span><!--BTTip@eof//-->@<span class=\"wager_color_red\">".$flOdds."</span>";
	}


/**
 * 組合 快樂 10分 下注內容資料 
 * @param	intLType 樂透種類序號
 * @param	intBT 下注種類
 * @param	intNum 號碼
 * @param	flOdds 賠率值
 * @param	intGNo 樂透期數
 * @param	flOdds_second 第二組賠率值
 * @param	arrJoinNumber 連碼號碼組 (Array)
 * @param	intJoinNo 連碼號碼組可產生之組數
 * @return	 String
 */
	function getWagerConditionsFor10M($intLType, $intBT, $intNum, $flOdds, $intGNo, $flOdds_second, $arrJoinNumber, $intJoinNo, $arrJNumOdds){
		$strNum = (string)$intNum;
		$strJoinNumber	= null;
		$strOddsTip = "";

		if (is_array($arrJoinNumber)) {
			//if($intBT >= 30 && $intBT <= 35){
			if(false){
				foreach ($arrJoinNumber as $intJN) {
					$strJoinNumber .= ' {Show-Mantissa'.$intJN.'-Name},';

				}

			}else{
				foreach ($arrJoinNumber as $strJN) {
					if($intNum == 0){
						if($intBT >= 30 && $intBT <= 35){
							$strJoinNumber .= '{Show-Mantissa'.((int)$strJN).'-Name}.';
						}else{
							$strJoinNumber .= $strJN .'.';
						}
					}else{
						$strJoinNumber .= '['.$strJN.']x';
					}
				}

				$arrOddsTip = array();
				foreach ($arrJNumOdds as $intJN => $strOdds){
					if($intBT >= 30 && $intBT <= 35){
						$arrOddsTip[] = ' {Show-Mantissa'.((int)$intJN).'-Name} (<span class="wager_color_red">'.$strOdds.'</span>)';
					}else{
						$arrOddsTip[] = sprintf("%02s", $intJN) .'(<span class="wager_color_red">'.$strOdds.'</span>)';
					}
				}
				$strOddsTip = implode(", ", $arrOddsTip);
			}
			$strJoinNumber = substr($strJoinNumber, 0, -1);
		}

		switch($intBT){
			case 1:
			case 5:
			case 6:
			case 7:
			case 8:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 2:
			case 9:
				$strNum = ($intNum == 0) ? "{Show-Odd-Name}":"{Show-Even-Name}";
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 3:
			case 10:
				$strNum = ($intNum == 0) ? "{Show-Over-Name}":"{Show-Under-Name}";
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 4:
				$strNum = ($intNum == 0) ? "{Show-SOdd-Name}":"{Show-SEven-Name}";
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- ".$strNum;
				break;

			case 15:
			case 16:
			case 17:
			case 18:
			case 19:
			case 20:
			case 21:
			case 22:
			case 23:
			case 24:
			case 25:
			case 26:
			case 27:
			case 28:
			case 30:
			case 31:
			case 32:
			case 33:
			case 34:
			case 35:
				$strNum = '{Show-Bet_Type'. $intBT .'-Name}';
				break;

			case 11:
				$intNormalNumSerie = floor($intNum / 10);
				$intNum = $intNum % 10;
				$strNum = ($intNum == 0) ? "{Show-Odd-Name}":"{Show-Even-Name}";
				$strBetTypeTip = "{Show-NormalNo".$intNormalNumSerie."-Name} -- ".$strNum;
				break;

			case 12:
				$intNormalNumSerie = floor($intNum / 10);
				$intNum = $intNum % 10;
				$strNum = ($intNum == 0) ? "{Show-Over-Name}":"{Show-Under-Name}";
				$strBetTypeTip = "{Show-NormalNo".$intNormalNumSerie."-Name} -- ".$strNum;
				break;

			case 13:
				$intNormalNumSerie = floor($intNum / 10);
				$intNum = $intNum % 10;
				$strNum = ($intNum == 0) ? "{Show-SOdd-Name}":"{Show-SEven-Name}";
				$strBetTypeTip = "{Show-NormalNo".$intNormalNumSerie."-Name} -- ".$strNum;
				break;

			case 29:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- {Show-Mantissa".(string)$intNum."-Name}";
				break;

			/*case 30:
			case 31:
			case 32:
			case 33:
			case 34:
			case 35:
				$strBetTypeTip = "{Show-Bet_Type".$intBT."-Name} -- (".$strJoinNumber.")";
				break;*/
		}

		if ($intBT >= 15 && $intBT <= 24) {
			if($intJoinNo > 1)$strTmp = '<br />{Show-MultiItems-Name}[&nbsp;<span class="wager_joinno_color">'.$intJoinNo.'</span>&nbsp;]&nbsp;{Show-Items-Name}';
			return '<span class="wager_color_blue"><!--Lotto//--> {Show-GameNo-Name} <b>'. sprintf("%03s", $intGNo) .'</b></span><br /><span class="wager_color_red">{Show-JoinNumber-Name} --&nbsp;'. $strNum .'</span>@ '. $strOddsTip .$strTmp.'<br /><span class="wager_join_color">'.$strJoinNumber.'</span>';
		}elseif ($intBT >= 25 && $intBT <= 28) {
			if($intJoinNo > 1)$strTmp = '<br />{Show-MultiItems-Name}[&nbsp;<span class="wager_joinno_color">'.$intJoinNo.'</span>&nbsp;]&nbsp;{Show-Items-Name}';
			return '<span class="wager_color_blue"><!--Lotto//--> {Show-GameNo-Name} <b>'. sprintf("%03s", $intGNo) .'</b></span><br /><span class="wager_color_red">{Show-NoIn-Name} --&nbsp;'. $strNum .'</span>@ '. $strOddsTip .$strTmp.'<br /><span class="wager_join_color">'.$strJoinNumber.'</span>';
		}elseif ($intBT >= 30 && $intBT <= 35) {
			if($intJoinNo > 1)$strTmp = '<br />{Show-MultiItems-Name}[&nbsp;<span class="wager_joinno_color">'.$intJoinNo.'</span>&nbsp;]&nbsp;{Show-Items-Name}';
			return '<span class="wager_color_blue"><!--Lotto//--> {Show-GameNo-Name} <b>'. sprintf("%03s", $intGNo) .'</b></span><br /><span class="wager_color_red">'. $strNum .'</span>@ '. $strOddsTip .$strTmp.'<br /><span class="wager_join_color">'.$strJoinNumber.'</span>';
		} else {
			return "<span class=\"wager_color_blue\"><!--Lotto//--> {Show-GameNo-Name} <b>".sprintf("%03s", $intGNo)."</b></span><br /><!--BTTip@bof//--><span class=\"wager_color_red\">".$strBetTypeTip."</span><!--BTTip@eof//-->@<span class=\"wager_color_red\">".$flOdds."</span>";
		}
	}


/**
 * 新增下注紀錄
 * @param	arrWagerCont 注單內容等陣列資訊
 * @param	arrWagerList 注金等陣列資訊
 * @return	 Array[?x]
 * ?x -> isError：true > 失敗，false -> 成功
 * 	 -> BetID：注單號碼
 * 	 -> ErrorMessage：錯誤訊息
 * 	 -> ErrorHiddenMessage：隱藏式錯誤訊息
 */
	function InsertWagerToDB($arrWagerCont, $arrWagerList){
		global $_ConnMaster;
		$strLog = "";
		$arrData = array();
		$arrData["isError"] = true;
		while(list($k, $v) = each($arrWagerCont)){
			if(strpos($k, "_x") > 0){
				$strF .= str_replace("_x", "", $k).",";
				$strV .= "'".$v."',";
			}else{
				$strF .= $k.",";
				$strV .= $v.",";
			}
		}
		$strSQL = "insert into `bet_BetListContent`(".$strF."BetDate,BetTime) values(".$strV."CURRENT_DATE(),CURRENT_TIME())";

		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$arrData["ErrorMessage"] = "WagerError";
			$arrData["ErrorHiddenMessage"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return $arrData;
		}
		$arrData["BetID"] = mysql_insert_id($_ConnMaster);

		$strLog = "BID：".$arrData["BetID"]."      \n".$strSQL."\n";
		$strF = "";
		$strV = "";
		while(list($k, $v) = each($arrWagerList)){
			if(strpos($k, "_x") > 0){
				$strF .= str_replace("_x", "", $k).",";
				$strV .= "'".$v."',";
			}else{
				$strF .= $k.",";
				$strV .= $v.",";
			}
		}
		$strSQL = "insert into `bet_BetListTmp`(".$strF."ID) values(".$strV.$arrData["BetID"].")";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$arrData["ErrorMessage"] = "WagerError";
			$arrData["ErrorHiddenMessage"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return $arrData;
		}
		$strSQL = "insert into `bet_BetList`(".$strF."ID) values(".$strV.$arrData["BetID"].")";
		$strLog .= $strSQL."\n";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$arrData["ErrorMessage"] = "WagerError";
			$arrData["ErrorHiddenMessage"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return $arrData;
		}
		//統計各階層注額
		//$arrDataa = setCountWagerForLayers($arrWagerList);
		//if($arrDataa["isError"] == true)return $arrDataa;

		//$arrData = array();
		$arrData["isError"] = false;
		$arrData["LogData"] = $strLog;
		return $arrData;
	}

/**
 * 統計各階層注額
 * @param	arrWagerList 注金等陣列資訊
 * @return	 false > 失敗，true -> 成功
 */
	function setCountWagerForLayers($arrWagerList){
		global $_ConnMaster;
		//if($arrWagerList["LottoID"] != 4)return true;

		//若是特碼 B  則轉為統計特碼 A
		if($arrWagerList["LottoID"] == 1 && $arrWagerList["Bet_Type"] == 28)$arrWagerList["Bet_Type"] = 1;

		$arrData["isError"] = true;
		$flExStake = $arrWagerList["MemStake"] * $arrWagerList["MemExchangeRate"];
		$flExPayOff = $arrWagerList["MemPayOff"] * $arrWagerList["MemExchangeRate"];
		$flRate2 = (1 - $arrWagerList["SubRate"]); //代理商
		$flRate3 = ($arrWagerList["SubRate"] - $arrWagerList["MainRate"]); //總代理
		$flRate4 = ($arrWagerList["MainRate"] - $arrWagerList["StockRate"]); //股東
		$flRate5 = ($arrWagerList["StockRate"] - $arrWagerList["DirectorRate"]); //總監
		$flRate6 = ($arrWagerList["DirectorRate"] - $arrWagerList["Layer6Rate"]); //業務總監

		$strSQL = "insert into `bet_RealTodayGame".$arrWagerList["LottoID"]."`(`GambleID`, `LottoID`, `Bet_Type`, `Number`, `tolWager`, `tolStake`, `tolPayOff`, `UserID`, `tolRealStake`, `tolRealPayOff`, `tolCommission`, `UpdateTime`) values ";
		$strSQLValue = "(".$arrWagerList["GambleID"].", ".$arrWagerList["LottoID"].", ".$arrWagerList["Bet_Type"].", ".$arrWagerList["Number"].", 1, '".$flExStake."', '".$flExPayOff."', %d, '%s', '%s', '%s', UNIX_TIMESTAMP())";
		$arrSQL = array();
		switch($arrWagerList["WagerType"]){
			case 0:
				$arrSQL[0] = sprintf($strSQLValue, $arrWagerList["SubID"], $flExStake*$flRate2, $flExPayOff*$flRate2, $flExStake*$flRate2*$arrWagerList["MemCommission"]);
			case 2:
				$arrSQL[1] = sprintf($strSQLValue, $arrWagerList["MainID"], $flExStake*$flRate3, $flExPayOff*$flRate3, $flExStake*$flRate3*$arrWagerList["SubCommission"]);
			case 3:
				$arrSQL[2] = sprintf($strSQLValue, $arrWagerList["StockID"], $flExStake*$flRate4, $flExPayOff*$flRate4, $flExStake*$flRate4*$arrWagerList["MainCommission"]);
			case 4:
				$arrSQL[3] = sprintf($strSQLValue, $arrWagerList["DirectorID"], $flExStake*$flRate5, $flExPayOff*$flRate5, $flExStake*$flRate5*$arrWagerList["StockCommission"]);
			case 5:
				$arrSQL[4] = sprintf($strSQLValue, $arrWagerList["Layer6ID"], $flExStake*$flRate6, $flExPayOff*$flRate6, $flExStake*$flRate6*$arrWagerList["DirectorCommission"]);
			case 6:
				break;

			default:
				$arrData["isError"] = false;
				return $arrData;
				break;
		}

		if(sizeof($arrSQL)){
			$strSQL .= implode(", ", $arrSQL)." ON DUPLICATE KEY UPDATE `tolWager` = `tolWager` + VALUES(`tolWager`), `tolStake` = `tolStake` + VALUES(`tolStake`), `tolPayOff` = `tolPayOff` + VALUES(`tolPayOff`), `tolRealStake` = `tolRealStake` + VALUES(`tolRealStake`), `tolRealPayOff` = `tolRealPayOff` + VALUES(`tolRealPayOff`), `tolCommission` = `tolCommission` + VALUES(`tolCommission`), `UpdateTime` = UNIX_TIMESTAMP()";
			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$arrData["ErrorMessage"] = "CountWagerForLayersError";
				$arrData["ErrorHiddenMessage"] = "Error1: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return $arrData;
			}
		}
		if($arrWagerList["WagerType"] < 2){
			$arrData["isError"] = false;
			return $arrData;
		}
		$strSQL = "insert into `bet_RealTodayGame".$arrWagerList["LottoID"]."`(`GambleID`, `LottoID`, `Bet_Type`, `Number`, `tolSuppleWager`, `tolSuppleStake`, `tolSupplePayOff`, `UserID`, `tolSuppleCommission`, `UpdateTime`) values (".$arrWagerList["GambleID"].", ".$arrWagerList["LottoID"].", ".$arrWagerList["Bet_Type"].", ".$arrWagerList["Number"].", 1, '".$flExStake."', '".$flExPayOff."', ";
		switch($arrWagerList["WagerType"]){
			case 2:
				$strSQL .= $arrWagerList["SubID"].", '".$flExStake*$arrWagerList["SubCommission"]."'";
				break;

			case 3:
				$strSQL .= $arrWagerList["MainID"].", '".$flExStake*$arrWagerList["MainCommission"]."'";
				break;

			case 4:
				$strSQL .= $arrWagerList["StockID"].", '".$flExStake*$arrWagerList["StockCommission"]."'";
				break;

			case 5:
				$strSQL .= $arrWagerList["DirectorID"].", '".$flExStake*$arrWagerList["DirectorCommission"]."'";
				break;

			case 6:
				$strSQL .= $arrWagerList["Layer6ID"].", '".$flExStake*$arrWagerList["Layer6Commission"]."'";
				break;
		}

		$strSQL .= ", UNIX_TIMESTAMP()) ON DUPLICATE KEY UPDATE `tolSuppleWager` = `tolSuppleWager` + VALUES(`tolSuppleWager`), `tolSuppleStake` = `tolSuppleStake` + VALUES(`tolSuppleStake`), `tolSupplePayOff` = `tolSupplePayOff` + VALUES(`tolSupplePayOff`), `tolSuppleCommission` = `tolSuppleCommission` + VALUES(`tolSuppleCommission`), `UpdateTime` = UNIX_TIMESTAMP()";
		//print "<br /><br /><br />\n\n".$strSQL."<br /><br /><br />\n\n";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$arrData["ErrorMessage"] = "CountWagerForLayersError";
			$arrData["ErrorHiddenMessage"] = "Error2: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return $arrData;
		}
		$arrData["isError"] = false;
		return $arrData;
	}

/**
 * 統計各階層注額
 * @param	arrWagerList 注金等陣列資訊
 * @return	 false > 失敗，true -> 成功
 */
	function setCountWagerForAllLayers($intLID, $intGID, $arrRealToday){
		global $_ConnMaster;

		$strSQL = "insert into `bet_RealTodayGame".$intLID."`(`GambleID`, `LottoID`, `Bet_Type`, `Number`, `UserID`, `tolWager`, `tolStake`, `tolPayOff`, `tolRealStake`, `tolRealPayOff`, `tolCommission`, `tolSuppleWager`, `tolSuppleStake`, `tolSupplePayOff`, `tolSuppleCommission`, `UpdateTime`) values ";

		$strSQLValue = "(".$intGID.", ".$intLID.", %d, %d, %d, %d, %f, %f, %f, %f, %f, %d, %f, %f, %f, UNIX_TIMESTAMP())";

		$arrSQL = array();
		foreach($arrRealToday as $intBT => $arrV1){
			foreach($arrV1 as $intNum => $arrV2){
				foreach($arrV2 as $intUID => $arrV3){
					$arrSQL[] = sprintf($strSQLValue, $intBT, $intNum, $intUID, $arrV3["W"], $arrV3["S"], $arrV3["P"], $arrV3["RS"], $arrV3["RP"], $arrV3["C"], $arrV3["SW"], $arrV3["SS"], $arrV3["SP"], $arrV3["SC"]);
				}
			}
		}

		if(sizeof($arrSQL)){
			$strSQL .= implode(", ", $arrSQL)." ON DUPLICATE KEY UPDATE `tolWager` = `tolWager` + VALUES(`tolWager`), `tolStake` = `tolStake` + VALUES(`tolStake`), `tolPayOff` = `tolPayOff` + VALUES(`tolPayOff`), `tolRealStake` = `tolRealStake` + VALUES(`tolRealStake`), `tolRealPayOff` = `tolRealPayOff` + VALUES(`tolRealPayOff`), `tolCommission` = `tolCommission` + VALUES(`tolCommission`), `tolSuppleWager` = `tolSuppleWager` + VALUES(`tolSuppleWager`), `tolSuppleStake` = `tolSuppleStake` + VALUES(`tolSuppleStake`), `tolSupplePayOff` = `tolSupplePayOff` + VALUES(`tolSupplePayOff`), `tolSuppleCommission` = `tolSuppleCommission` + VALUES(`tolSuppleCommission`), `UpdateTime` = UNIX_TIMESTAMP()";
			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "CountWagerForAllLayersError";
				$GLOBALS["errorhidden"] = "Error1: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
		}
		return true;
	}

/**
 * 新增連碼下注-場次號碼下注累積紀錄
 * @param	MemID：會員
 * @param	SubID：代理
 * @param	MainID：總代理
 * @param	StockID： 股東
 * @param	DirectorID： 總監
 * @param	Layer6ID：業務總監
 * @param	intGID：GambleID
 * @param	intBT：Bet_Type
 * @param	intBetListID：注單序號
 * @param	arrJoinNumber：下注號碼陣列，請先將號碼組成一串號碼 , 小於10的要補零 , ex：1,2,3 -> 010203;
 * @param	intStake：下注金額
 * @param	flOdds：賠率
 * @param	flOdds2：賠率2
 * @param	arrJoinNumOdds：連碼每組號碼的賠率陣列
 * @return	 Array[?x]
 * ?x -> isError：true > 失敗，false -> 成功
 *    -> BetID：注單號碼
 *    -> ErrorMessage：錯誤訊息
 *    -> ErrorHiddenMessage：隱藏式錯誤訊息
 */
	function InsertParlaysNumberEvenToDB($MemID, $SubID, $MainID, $StockID, $DirectorID, $Layer6ID, $intGID, $intBT, $intBetListID, $arrJoinNumber, $intStake, $flOdds, $flOdds2, $arrJoinNumOdds = null) {
		global $_ConnMaster;

		$strSQL = "";
		$arrData["isError"] 	= true;

		if(!$MemID || !$SubID || !$MainID || !$StockID || !$DirectorID || !$Layer6ID || !$intGID || !$intBT || !is_array($arrJoinNumber) || !$intStake){
			$arrData["ErrorMessage"] 	= "EvenError";
			$arrData["ErrorHiddenMessage"]	= "Error: Function InsertParlaysNumberEvenToDB error!!";
			return $arrData;
		}
		$tmpSQL = "('$MemID', '$SubID', '$MainID', '$StockID', '$DirectorID', '$Layer6ID', '$intGID', '$intBT', '$intBetListID', '{Number}', '$intStake', '{MemPayOff}', '{MemPayOff2}', '{Ball1}', '{Ball2}', '{Ball3}', '{Ball4}', '{Ball5}', '{Ball6}', '{Odds1}', '{Odds2}')";
		$arrSQL = array();
		foreach ($arrJoinNumber as $key => $strNum) {
			$arrJN = explode('.', $strNum);
			sort($arrJN);
			$arrSQL[$key] = $tmpSQL;
			$arrSQL[$key] = str_replace("{Number}", sprintf("%012s", join("", $arrJN)), $arrSQL[$key]);
			$arrSQL[$key] = str_replace("{Ball1}", ($arrJN[0] == null?-1:$arrJN[0]), $arrSQL[$key]);
			$arrSQL[$key] = str_replace("{Ball2}", ($arrJN[1] == null?-1:$arrJN[1]), $arrSQL[$key]);
			$arrSQL[$key] = str_replace("{Ball3}", ($arrJN[2] == null?-1:$arrJN[2]), $arrSQL[$key]);
			$arrSQL[$key] = str_replace("{Ball4}", ($arrJN[3] == null?-1:$arrJN[3]), $arrSQL[$key]);
			$arrSQL[$key] = str_replace("{Ball5}", ($arrJN[4] == null?-1:$arrJN[4]), $arrSQL[$key]);
			$arrSQL[$key] = str_replace("{Ball6}", ($arrJN[5] == null?-1:$arrJN[5]), $arrSQL[$key]);
			if($arrJoinNumOdds == null){
				$flPayOff = $intStake*($flOdds - 1);
				$flPayOff2 = $intStake*($flOdds2 - 1);
				$arrSQL[$key] = str_replace("{Odds1}", $flOdds, $arrSQL[$key]);
				$arrSQL[$key] = str_replace("{Odds2}", $flOdds2, $arrSQL[$key]);
			}else{
				$flPayOff = $intStake*($arrJoinNumOdds[$strNum] - 1);
				$flPayOff2 = 0;
				$arrSQL[$key] = str_replace("{Odds1}", $arrJoinNumOdds[$strNum], $arrSQL[$key]);
				$arrSQL[$key] = str_replace("{Odds2}", 0, $arrSQL[$key]);
			}
			$arrSQL[$key] = str_replace("{MemPayOff}", $flPayOff, $arrSQL[$key]);
			$arrSQL[$key] = str_replace("{MemPayOff2}", $flPayOff2, $arrSQL[$key]);
		}

		$strSQL = "INSERT INTO `bet_ParlaysNumberEven` (`MemID` , `SubID` , `MainID` , `StockID` , `DirectorID` , `Layer6ID` , `GambleID` , `Bet_Type` , `BetListID` , `Number` , `MemStake` , `MemPayOff`, `MemPayOff2`, `Ball1`, `Ball2`, `Ball3`, `Ball4`, `Ball5`, `Ball6`, `Odds1`, `Odds2`) VALUES ".join(",", $arrSQL);

		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$arrData["ErrorMessage"] = "EvenError";
			$arrData["ErrorHiddenMessage"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:". $strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return $arrData;	
		}

		$arrData["isError"] = false;
		$arrData["LogData"] = $strLog;
		return $arrData;
	}

/**
 * 押碼跳動
 * @param	arrGD：下注資料陣列
 * @param	dbRealStake：實際下注金額
 * @param	dbRealPayOff：實際派彩
 * @param	flAllOdds：單雙、大小賠率總和
 * @param	dbRealRate：公司成數 x 匯率值
 * @return	 Array[?x]
 * ?x -> isError：true > 失敗，false -> 成功
 * 	 -> ErrorMessage：錯誤訊息
 * 	 -> ErrorHiddenMessage：隱藏式錯誤訊息
 */
	function WagerJump($arrGD, $intStake, $intPayOff, $arrBP, $flAllOdds, $dbRealRate, $dbCommission, $arrPlusStake){
		global $_KSysParam;
		$isRealJumpWager = $_KSysParam["isRealJumpWager"];
		$isRealPayOffJumpWager = $_KSysParam["isRealPayOffJumpWager"];
		if(empty($isRealJumpWager))$isRealJumpWager = 0;
		if(empty($isRealPayOffJumpWager))$isRealPayOffJumpWager = 0;	//是否採用派彩
		$arrData["isError"] = true;

		$isOtherUpdate = false;
		$arrBT = array($arrGD["Bet_Type"]);
		$strLTypeBT = $arrGD["LType"]."-".$arrGD["Bet_Type"];

		$tolStake = doubleval($intStake) + doubleval($arrPlusStake["Stake"]);
		$tolRealStake = doubleval($intStake*$dbRealRate) + doubleval($arrPlusStake["RealStake"]);
		$tolPayOff = doubleval($intPayOff) + doubleval($arrPlusStake["PayOff"]);
		$tolRealPayOff = doubleval($intPayOff*$dbRealRate) + doubleval($arrPlusStake["RealPayOff"]);
		$tolCommission = $tolRealStake*$dbCommission;
		$isUseFirstJump = false;
		//若是七星彩  且尚無任何押碼跳動次數
		if($arrGD["LType"] == 3 && $arrGD["JumpNo"] == 0)$isUseFirstJump = true;
		//print $tolStake." = ".$tolRealStake." = ".$tolPayOff." = ".$tolRealPayOff." = ".$intStake." = ".$intPayOff." = ";
		//print_r($arrPlusStake);
		//exit();
		switch($strLTypeBT){
			//不需要押碼跳動
			case "2-83":	//中 3保 3
				//若最高下注總額，已超過限額，即停押壓
				if($isRealJumpWager == 0){
					$flMaxStakeGap = doubleval($arrGD["tolStake"]) + $tolStake;
				}else{
					$flMaxStakeGap = doubleval($arrGD["tolRealStake"]) + $tolRealStake;
				}

				if($flMaxStakeGap >= doubleval($arrBP["MaxStakeGap"])){
					$strStop = ", isStopBet = 1";
					$GLOBALS["errormessage"] = "NotOverMaxStakeGap";
					return $arrData;
				}
				//押碼跳動
				if($isRealPayOffJumpWager == 1){	//採用派彩間隔
					$tolJumpStake = $tolRealPayOff;
				}else{
					$tolJumpStake = ($isRealJumpWager == 0)?$tolStake:$tolRealStake;
				}

				//統計用條件
				$strOhterCase = ", tolWager = tolWager + 1, tolJumpStake = ".($tolJumpStake == 0?"0, JumpNo = JumpNo + 1":"tolJumpStake + ".$tolJumpStake).", tolStake = tolStake + ".$tolStake.", tolRealStake = tolRealStake + ".$tolRealStake.", tolCommission = tolCommission + ".$tolCommission.", tolPayOff = tolPayOff + ".$tolPayOff.", tolRealPayOff = tolRealPayOff + ".($tolRealPayOff).$strStop;

				if(empty($intOID)){
					$intOID = "OddsID";
					$flOdds = "Odds";
				}
				//更新賠率表 bet_TodayGame
				if(!UpdateTodayGame($arrGD["GambleID"], $arrGD["LottoID"], $arrGD["Bet_Type"], $arrGD["Number"], $intOID, $flOdds, $strOhterCase))return $arrData;

				//更新 TodayGame 檔案
				if(!MakeTodayGameFile($arrGD["LottoID"], $arrGD["Bet_Type"]))return $arrData;

				$arrData["isError"] = false;
				return $arrData;
				break;


			//單雙、大小
			case "1-12":
			case "1-13":
			case "1-16":
			case "1-27":
			case "1-2":
			case "1-3":
			case "1-5":
			case "1-6":
			case "2-52":
			case "2-53":
			case "2-55":
			case "2-56":
			case "2-58":
			case "2-59":
			case "2-62":
			case "2-63":
			case "2-84":
			case "2-85":
			case "2-86":
			case "3-14":
			case "3-15":
			case "3-16":
			case "3-17":
			case "4-2":
			case "4-3":
			case "4-4":
			case "4-9":
			case "4-10":
			case "4-11":
			case "4-12":
			case "4-13":
				if($arrGD["LType"] == 1 && ($arrGD["Bet_Type"] == 12 || $arrGD["Bet_Type"] == 13 || $arrGD["Bet_Type"] == 27)){
					$intNum = ($arrGD["Number"] % 10 == 0)?($arrGD["Number"] + 1):floor($arrGD["Number"] / 10)*10;

				}elseif($arrGD["LType"] == 3 && ($arrGD["Bet_Type"] == 14 || $arrGD["Bet_Type"] == 15 || $arrGD["Bet_Type"] == 16 || $arrGD["Bet_Type"] == 17)){
					$intNum = ($arrGD["Number"] % 10 == 0)?($arrGD["Number"] + 1):floor($arrGD["Number"] / 10)*10;

				}elseif($arrGD["LType"] == 4 && ($arrGD["Bet_Type"] == 11 || $arrGD["Bet_Type"] == 12 || $arrGD["Bet_Type"] == 13)){
					$intNum = ($arrGD["Number"] % 10 == 0)?($arrGD["Number"] + 1):floor($arrGD["Number"] / 10)*10;

				}else{
					$intNum = ($arrGD["Number"] == 0)?1:0;
				}
				$arrGD2 = getTodayGameArrayData($arrGD["LottoID"], $arrGD["LType"], $arrGD["GambleID"], $arrGD["Bet_Type"], $intNum);

				//若最高派彩總額，已超過限額，即停押壓
				if($isRealJumpWager == 0){
					$flMaxStakeGap = doubleval($arrGD["tolStake"] - $arrGD["tolSuppleStake"]) + $tolStake - doubleval($arrGD2["tolStake"]);
				}else{
					$flMaxStakeGap = doubleval($arrGD["tolRealStake"] - $arrGD["tolSuppleStake"]) +$tolRealStake - doubleval($arrGD2["tolRealStake"]);
				}

				if($flMaxStakeGap >= doubleval($arrBP["MaxStakeGap"])){
					$strStop = ", isStopBet = 1";
					$GLOBALS["errormessage"] = "NotOverMaxStakeGap";
					return $arrData;
				}

				//押碼跳動
				if($isRealPayOffJumpWager == 1){	//採用派彩間隔
					$tolJumpStake = doubleval($arrGD["tolJumpStake"]) + $tolRealPayOff;
					$flStakeJump = doubleval($arrBP["PayOffJump"]);
					$flStakeJumpRate = floatval($arrBP["PayOffJumpRate"] / 100)*floatval($arrGD["Odds"]);
				}else{
					$tolJumpStake = doubleval($arrGD["tolJumpStake"]) + ($isRealJumpWager == 0?$tolStake:$tolRealStake);
					$flStakeJump = ($isUseFirstJump)?doubleval($arrBP["StakeJump1"]):doubleval($arrBP["StakeJump"]);
					$flStakeJumpRate = floatval($arrBP["StakeJumpRate"]);
				}
				//print $tolJumpStake .">=". doubleval($arrBP["StakeJump"]);

				if(($tolJumpStake - doubleval($arrGD2["tolJumpStake"])) >= $flStakeJump){
					$flOdds = floatval($arrGD["Odds"]) - $flStakeJumpRate;
					if($flOdds < 0)$flOdds = 0;
					$flOdds = ConvertOdds($arrGD["LType"], $arrGD["Bet_Type"], $flOdds);
					$flOdds2 = floatval($flAllOdds) - $flOdds;
					$flOdds2 = ConvertOdds($arrGD["LType"], $arrGD["Bet_Type"], $flOdds2);
					$tolJumpStake = 0;

					//載入押碼跳動後賠率
					if(!$intOID = InsertBetTypeOdds($arrGD["GambleID"], $arrGD["LottoID"], $arrGD["Bet_Type"], $arrGD["Number"], $flOdds, 1, $_SESSION["Member_Info"] -> Account))return $arrData;

					//載入另一方押碼跳動後賠率
					if(!$intOID2 = InsertBetTypeOdds($arrGD["GambleID"], $arrGD["LottoID"], $arrGD["Bet_Type"], $intNum, $flOdds2, 1, $_SESSION["Member_Info"] -> Account))return $arrData;

					//更新賠率表 bet_TodayGame
					if(!UpdateTodayGame($arrGD["GambleID"], $arrGD["LottoID"], $arrGD["Bet_Type"], $intNum, $intOID2, $flOdds2, ", tolJumpStake = 0"))return $arrData;
				}  //  if(($tolJumpStake - doubleval($arrGD2["tolJumpStake"])) >= $flStakeJump){

				//統計用條件
				$strOhterCase = ", tolWager = tolWager + 1, tolJumpStake = ".$tolJumpStake.($tolJumpStake == 0?", JumpNo = JumpNo + 1":"").", tolStake = tolStake + ".$tolStake.", tolRealStake = tolRealStake + ".$tolRealStake.", tolCommission = tolCommission + ".$tolCommission.", tolPayOff = tolPayOff + ".$tolPayOff.", tolRealPayOff = tolRealPayOff + ".$tolRealPayOff.$strStop;
				//print $strOhterCase;
				if(empty($intOID)){
					$intOID = "OddsID";
					$flOdds = "Odds";
				}
				//更新賠率表 bet_TodayGame
				if(!UpdateTodayGame($arrGD["GambleID"], $arrGD["LottoID"], $arrGD["Bet_Type"], $arrGD["Number"], $intOID, $flOdds, $strOhterCase))return $arrData;

				//若有押碼跳動，及更新 TodayGame 檔案
				if(!MakeTodayGameFile($arrGD["LottoID"], $arrGD["Bet_Type"]))return $arrData;
				break;

			case "1-7":
			case "1-8":
			case "1-9":
			case "1-10":
			case "1-11":
				$intNum = ($arrGD["Number"] == 0)?1:0;
				$arrGD2 = getTodayGameArrayData($arrGD["LottoID"], $arrGD["LType"], $arrGD["GambleID"], $arrGD["Bet_Type"], $intNum);

				/*
				//若最高派彩總額，已超過限額，即停押
				if($isRealJumpWager == 0){
					$flMaxStakeGap = doubleval($arrGD["tolStake"]) + $tolStake - doubleval($arrGD2["tolStake"]);
				}else{
					$flMaxStakeGap = doubleval($arrGD["tolRealStake"]) + $tolRealStake - doubleval($arrGD2["tolRealStake"]);
				}
				//print $flMaxStakeGap;
				if($flMaxStakeGap >= doubleval($arrBP["MaxStakeGap"])){
					$strStop = ", isStopBet = 1";
					$GLOBALS["errormessage"] = "NotOverMaxStakeGap";
					return $arrData;
				}
				*/

				//統計用條件
				$strOhterCase = ", tolWager = tolWager + 1, tolStake = tolStake + ".$tolStake.", tolRealStake = tolRealStake + ".$tolRealStake.", tolCommission = tolCommission + ".$tolCommission.", tolPayOff = tolPayOff + ".$tolPayOff.", tolRealPayOff = tolRealPayOff + ".$tolRealPayOff.$strStop;

				if(empty($intOID)){
					$intOID = "OddsID";
					$flOdds = "Odds";
				}
				//更新賠率表 bet_TodayGame
				if(!UpdateTodayGame($arrGD["GambleID"], $arrGD["LottoID"], $arrGD["Bet_Type"], $arrGD["Number"], $intOID, $flOdds, $strOhterCase))return $arrData;

				//若有押碼跳動，及更新 TodayGame 檔案
				if(!MakeTodayGameFile($arrGD["LottoID"], $arrGD["Bet_Type"]))return $arrData;
				break;

			case "1-28":	//特碼 B
			case "1-1":		//特碼 A
				$isOtherUpdate = true;
				$arrBT = array(1, 28);
				
				$_flABGapOdds = $_KSysParam["SpecialNumberABOddsGap"];
				$_flABGapOdds2 = $_KSysParam["SpecialNumberABOddsGap2"];
				$_flABGapOdds3 = $_KSysParam["SpecialNumberABOddsGap3"];
				$_flAOdds2 = $_KSysParam["SpecialNumberAOdds2"];
				$_flAOdds3 = $_KSysParam["SpecialNumberAOdds3"];
				$_flBOdds2 = $_KSysParam["SpecialNumberBOdds2"];
				$_flBOdds3 = $_KSysParam["SpecialNumberBOdds3"];
				$flABGapOdds = $_flABGapOdds;
			default:
				$arrNoLimitMaxStakeGap[4] = array(15 => 1, 16 => 1, 17 => 1, 18 => 1, 19 => 1, 20 => 1, 21 => 1, 22 => 1, 23 => 1, 24 => 1, 25 => 1, 26 => 1, 27 => 1, 28 => 1, 30 => 1, 31 => 1, 32 => 1, 33 => 1, 34 => 1, 35 => 1);

				if(!$arrNoLimitMaxStakeGap[ $arrGD["LType"] ][ $arrGD["Bet_Type"] ]){
					//若最高下注總額，已超過限額，即停押壓
					if($isRealJumpWager == 0){
						$flMaxStakeGap = doubleval($arrGD["tolStake"] - $arrGD["tolSuppleStake"]) + $tolStake;
					}else{
						$flMaxStakeGap = doubleval($arrGD["tolRealStake"] - $arrGD["tolSuppleStake"]) + $tolRealStake;
					}

					if($flMaxStakeGap >= doubleval($arrBP["MaxStakeGap"])){
						$strStop = ", isStopBet = 1";
						$GLOBALS["errormessage"] = "NotOverMaxStakeGap";
						return $arrData;
					}
				} // if(!$arrNoLimitMaxStakeGap[$arrGD["LType"]][$arrGD["Bet_Type"]]){

				//押碼跳動
				if($isRealPayOffJumpWager == 1){	//採用派彩間隔
					$tolJumpStake = $tolRealPayOff;
					$flStakeJump = doubleval($arrBP["PayOffJump"]);
					$flStakeJumpRate = floatval($arrBP["PayOffJumpRate"] / 100)*(floatval($arrGD["Odds"]) - 1);
				}else{
					$tolJumpStake = ($isRealJumpWager == 0)?$tolStake:$tolRealStake;
					$flStakeJump = ($isUseFirstJump)?doubleval($arrBP["StakeJump1"]):doubleval($arrBP["StakeJump"]);
					$flStakeJumpRate = floatval($arrBP["StakeJumpRate"]);
				}
				$tolJumpStakeAll = doubleval($arrGD["tolJumpStake"]) + $tolJumpStake;

				if($tolJumpStakeAll >= $flStakeJump){
					$flOdds = floatval($arrGD["Odds"]) - $flStakeJumpRate;

					if($arrGD["LType"] == 1){
						if($arrGD["Bet_Type"] == 28){
							if($flOdds <= $_flBOdds2)$flABGapOdds = $_flABGapOdds2;
							if($flOdds <= $_flBOdds3)$flABGapOdds = $_flABGapOdds3;
							$flOdds -= $flABGapOdds;	//改回特碼A
							$flABGapOdds = $_flABGapOdds;
							if($flOdds <= $_flAOdds2)$flABGapOdds = $_flABGapOdds2;
							if($flOdds <= $_flAOdds3)$flABGapOdds = $_flABGapOdds3;

						}elseif($arrGD["Bet_Type"] == 1){
							if($flOdds <= $_flAOdds2)$flABGapOdds = $_flABGapOdds2;
							if($flOdds <= $_flAOdds3)$flABGapOdds = $_flABGapOdds3;
						}
					} // if($arrGD["LType"] == 1){

					if($flOdds < 1)$flOdds =1;
					$flOdds = ConvertOdds($arrGD["LType"], $arrGD["Bet_Type"], $flOdds);

					//載入押碼跳動後賠率
					if($isOtherUpdate){	//額外處理
						if(!$intOID = InsertBetTypeOdds($arrGD["GambleID"], $arrGD["LottoID"], 1, $arrGD["Number"], $flOdds, 1, $_SESSION["Member_Info"] -> Account))return $arrData;
						if(!$intOID2 = InsertBetTypeOdds($arrGD["GambleID"], $arrGD["LottoID"], 28, $arrGD["Number"], $flOdds + $flABGapOdds, 1, $_SESSION["Member_Info"] -> Account))return $arrData;
						$intBT = 28;
						$flOdds2 = $flOdds + $flABGapOdds;
						if($arrGD["Bet_Type"] == 28){
							$intBT = 1;
							$intT = $intOID2;
							$intOID2 = $intOID;
							$intOID = $intT;
							$flOdds2 = $flOdds;
							$flOdds += $flABGapOdds;
						}
						//更新賠率表 bet_TodayGame
						if(!UpdateTodayGame($arrGD["GambleID"], $arrGD["LottoID"], $intBT, $arrGD["Number"], $intOID2, $flOdds2, ", tolJumpStake = 0"))return $arrData;
					}else{
						if(!$intOID = InsertBetTypeOdds($arrGD["GambleID"], $arrGD["LottoID"], $arrGD["Bet_Type"], $arrGD["Number"], $flOdds, 1, $_SESSION["Member_Info"] -> Account))return $arrData;
					}  //if($isOtherUpdate){
					//押碼累積跳動金額歸零
					$tolJumpStakeAll = 0;
				}  //if($tolJumpStake >= $flStakeJump){

				//統計用條件
				$strOhterCase = ", tolWager = tolWager + 1, tolJumpStake = ".($tolJumpStakeAll == 0?"0, JumpNo = JumpNo + 1":" tolJumpStake + ".$tolJumpStake).", tolStake = tolStake + ".$tolStake.", tolRealStake = tolRealStake + ".$tolRealStake.", tolCommission = tolCommission + ".$tolCommission.", tolPayOff = tolPayOff + ".$tolPayOff.", tolRealPayOff = tolRealPayOff + ".$tolRealPayOff.$strStop;

				if(empty($intOID)){
					$intOID = "OddsID";
					$flOdds = "Odds";
				}
				//更新賠率表 bet_TodayGame
				if(!UpdateTodayGame($arrGD["GambleID"], $arrGD["LottoID"], $arrGD["Bet_Type"], $arrGD["Number"], $intOID, $flOdds, $strOhterCase))return $arrData;

				//更新 TodayGame 檔案
				if($tolJumpStakeAll == 0){
					foreach($arrBT as $intBT){
						if(!MakeTodayGameFile($arrGD["LottoID"], $intBT))return $arrData;
					}
				}
				break;
		}
		
		$arrData["isError"] = false;
		return $arrData;
	}


/**
從資料庫取得單場、單注、信用額度陣列檔
 * @param intUserID 使用者序號
 * @param intGID 操盤序號
 * @param intBT 下注遊戲種類序號
 * @param strJoinNumber 組合號碼
 * @param intWagerType
 * @return int -> 成功，false -> 失敗
*/
	function getWagerLimitGoldByJoinNumber($intUserID, $intGID, $intBT, $strJoinNumber, $intWagerType = 0){
		global $_Conn, $$_Conn;

		$strSQL = "select sum(a.MemStake) as SumStake from `bet_BetListTmp` a, `bet_BetListContent` b where a.ID = b.ID and a.MemID = ".(string)$intUserID." and a.GambleID = ".$intGID." and a.isPayOff >= 0 and a.Bet_Type = ".$intBT." and a.WagerType = ".(string)$intWagerType." and b.JoinNumber = '".$strJoinNumber."'";
		//print $strSQL."\n";
		if (!$RS = PMA_mysql_query($strSQL, $$_Conn)) {
			$GLOBALS["errormessage"] = "Sum Gold Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		$Row = PMA_mysql_fetch_object($RS);
		return $Row -> SumStake;
	}


/**
從資料庫取得單場、單注、信用額度陣列檔
 * @param	intUserID：使用者序號
 * @return	 Array -> 成功，false -> 失敗
*/
	function getWagerArrayGoldByDB($intUserID, $intWagerType = 0){
		global $_Conn, $$_Conn;

		$strSQL = "select Bet_Type, GambleID, Number, sum(MemStake) as cc, sum(IF(MemResult = 0, MemStake, 0)) as dc, sum(IF(MemResult > 0, MemResult + MemStake, 0)) as rc, sum( MemStake*MemCommission) as mc from `bet_BetListTmp` where MemID = ".(string)$intUserID." and PayupDate >= Current_Date() and isPayOff >= 0 and WagerType = ".(string)$intWagerType." group by Bet_Type, GambleID, Number";

		if (!$RS = PMA_mysql_query($strSQL, $$_Conn)) {
			$GLOBALS["errormessage"] = "Lotto Serie No Data not Int!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		$arrMemStake = array();
		while ($Row = PMA_mysql_fetch_object($RS)) {
			$arrMemStake[$Row -> Bet_Type][$Row -> GambleID][$Row -> Number] = $Row -> cc;
			$arrMemStake[$Row -> Bet_Type][$Row -> GambleID]["_SUM"] += $Row -> cc;
			$arrMemStake[$Row -> Bet_Type]["_SUM"] += $Row -> cc;
			if(__isUseOldCreditLine == 1){
				$arrMemStake["_SUM"] += round($Row -> cc);
			}else{
				$arrMemStake["_SUM"] += round($Row -> cc - $Row -> rc - $Row -> mc);
			}
			$arrMemStake["_Wager"] += round($Row -> dc);
			$arrMemStake["_Result"] += round($Row -> cc - $Row -> dc - $Row -> rc - $Row -> mc);
		}
		return $arrMemStake;
	}


/**
產生單場、單注、信用額度陣列檔
 * @param	intUserID：使用者序號
 * @return	 true -> 成功，false -> 失敗
*/
	function getWagerArrayGold($intUserID){
		$arrMemStake = getWagerArrayGoldByDB($intUserID);
		if($arrMemStake === false)return false;

		$strFile = __Root_Path."/tmp/credit-".$intUserID.".php";
		$strCon = "<?php\n\$_arrMemStake=unserialize(\"".addslashes(serialize($arrMemStake))."\");\n?".">";

		if(!writeFile($strFile, $strCon, "w"))return false;
		return true;
	}

/**
 * 新增連碼下注紀錄
 * @param	intBListID 注單序號
 * @param	intGID 操盤號
 * @param	arrBT 下注種類陣列
 * @param	arrJoinNumber 下注號碼陣列
 * @param	arrOdds 賠率陣列
 * @param	arrOddsID 賠率ID 陣列
 * @return	 Array[?x]
 * ?x -> isError：true > 失敗，false -> 成功
 *    -> BetID：注單號碼
 *    -> ErrorMessage：錯誤訊息
 *    -> ErrorHiddenMessage：隱藏式錯誤訊息
 */
	function InsertParlaysThroughToDB($intBListID, $intGID, $arrBT, $arrJoinNumber, $arrOdds, $arrOddsID) {
		global $_ConnMaster;

		$strSQL 		= null;
		$arrData["isError"] 	= true;

		if(!$intBListID || !$intGID || !is_array($arrBT) || !is_array($arrJoinNumber) || !is_array($arrOdds) || !is_array($arrOddsID)){
			$arrData["ErrorMessage"] 	= "ParameterError";
			$arrData["ErrorHiddenMessage"] = "Error: Function parameter error!!";
			$arrData["ErrorHiddenMessage"] .= "\n".$intBListID."=".$intGID;
			return $arrData;
		}

		$strSQL = 'INSERT INTO `bet_ParlaysNumber` (`ID` ,`BetListID` ,`GambleID` ,`Bet_Type` ,`Number` ,`WinRate` ,`isCancel`, `OddsID`, `Odds`) VALUES ';

		foreach ($arrJoinNumber as $key => $strNum) {
			$strSQL .= "('', '".$intBListID."', '".$intGID."', '".$arrBT[$key]."', '".$strNum."', '0', '0', '".$arrOddsID[$key]."', '".$arrOdds[$key]."'),";
		}

		$strSQL = substr($strSQL, 0, -1);
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$arrData["ErrorMessage"] = "WagerError";
			$arrData["ErrorHiddenMessage"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$Insert_Sql."\nLine:".__LINE__."\nPage:".__FILE__;
			return $arrData;	
		}

		$arrData["isError"] = false;
		$arrData["LogData"] = $strLog;
		return $arrData;
	}


/**
 * 補貨外調下注
 * @param	intLID 樂透序號
 * @param	intLType 樂透種類序號
 * @param	intBT 下注種類
 * @param	strNum 下注號碼
 * @param	intStake 下注金額
 * @param	OddsID 賠率ID
 * @param	flOdds 賠率
 * @param	OddsID2 賠率ID2
 * @param	flOdds2 賠率2
 * @param	strChoiceNumber 所選擇號碼
 * @param	CheckKey1 檢查值1
 * @param	CheckKey2 檢查值2
 * @param	intSuppleWagerID 補貨單號
 * @return	 Array
 */
	function SuppleWager($intLID, $intLType, $intBT, $strNum, $intStake, $intOID, $flOdds, $intOID2, $flOdds2, $strChoiceNumber, $CheckKey1, $CheckKey2, $intSuppleWagerID){
		global $_KSysParam, $_intLang;

		if($intLType == 1 && $intBT >= 7 && $intBT <= 11){
			$strNum = str_replace(",", "|", $strNum);
			if(!empty($intOID2))$intOID .= "|".$intOID2;
			if(!empty($flOdds2))$flOdds .= "|".$flOdds2;

			$strLink = "http://".$_KSysParam[SuppleIP]."/member/hidden.php?userid=".$_SESSION["Admin_Info"] -> ID."&lang=".$_intLang."&Account=".$_KSysParam[SuppleAccount]."&LottoID=".$intLID."&Bet_Type=".$intBT."&JoinNumber=".$strNum."&OddsID=".$intOID."&Odds=".$flOdds."&StakeMoney=".$intStake."&CheckKey1=".$CheckKey1."&CheckKey2=".$CheckKey2."&suppleid=".$intSuppleWagerID;

		}elseif($intLType == 1 && $intBT >= 31 && $intBT <= 43){
			$strLink = "http://".$_KSysParam[SuppleIP]."/member/hidden.php?userid=".$_SESSION["Admin_Info"] -> ID."&lang=".$_intLang."&Account=".$_KSysParam[SuppleAccount]."&LottoID=".$intLID."&Bet_Type=".$intBT."&Number=".$strNum."&JoinNumber=".$strChoiceNumber."&OddsID=".$intOID."&Odds=".$flOdds."&StakeMoney=".$intStake."&CheckKey1=".$CheckKey1."&CheckKey2=".$CheckKey2."&suppleid=".$intSuppleWagerID;

		}else{
			$strLink = "http://".$_KSysParam[SuppleIP]."/member/hidden.php?userid=".$_SESSION["Admin_Info"] -> ID."&lang=".$_intLang."&Account=".$_KSysParam[SuppleAccount]."&LottoID=".$intLID."&Bet_Type=".$intBT."&Number=".$strNum."&OddsID=".$intOID."&Odds=".$flOdds."&StakeMoney=".$intStake."&CheckKey1=".$CheckKey1."&CheckKey2=".$CheckKey2."&suppleid=".$intSuppleWagerID."&ChoiceNumber=".$strChoiceNumber;
		}

		$ch = curl_init ();
		curl_setopt($ch,CURLOPT_URL, $strLink);
		//curl_setopt ($ch, CURLOPT_VERBOSE, 0);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt ($ch, CURLOPT_HEADER, 0);
		curl_setopt ($ch, CURLOPT_HTTPHEADER, array(
			"Accept:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/x-shockwave-flash, */*",
			"User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)",
			"Host:".$_KSysParam[SuppleUrl],
			"Connection:Keep-Alive"));
		$strCon = curl_exec ($ch);
		curl_close ($ch);
		if($_SESSION["DEBUG"])print $strCon;
		//$strCon = join("", file($strLink));
		//print $strLink;
		$arrResult["isWager"] = false;

		/*if($_intLang == 1){
			if("UTF-8" != mb_detect_encoding($strCon, "EUC-CN,BIG5"))$strCon = iconv("BIG5", "UTF-8", $strCon);
		}elseif($_intLang == 3){
			if("UTF-8" != mb_detect_encoding($strCon, "EUC-CN,UTF-8"))$strCon = iconv("GB2312", "UTF-8", $strCon);
		}*/
		if(trim($strCon) == ""){
			$arrResult["WagerCon"] = "Wager Error!!";
		}elseif(preg_match("/Succ Tip/", $strCon)){
			preg_match("/<!--Succ Tip\/\/-->(.+)<!--Succ Tip\/\/-->/s", $strCon, $arrCon);
			$arrResult["WagerTip"] = $arrCon[1];
			preg_match("/<!--Succ Con\/\/-->(.+)<!--Succ Con\/\/-->/s", $strCon, $arrCon);
			$arrResult["WagerCon"] = $arrCon[1];
			$arrResult["isWager"] = true;
		}else{
			preg_match("/<!--Err Con\/\/-->(.+)<!--Err Con\/\/-->/s", $strCon, $arrCon);
			$arrResult["WagerCon"] = $arrCon[1];
		}
		return $arrResult;
	}


/**
 * 階層補貨外調下注
 * @param	intLID 樂透序號
 * @param	intLType 樂透種類序號
 * @param	intGID 操盤序號
 * @param	intBT 下注種類
 * @param	strNum 下注號碼
 * @param	intStake 下注金額
 * @param	OddsID 賠率ID
 * @param	flOdds 賠率
 * @param	OddsID2 賠率ID2
 * @param	flOdds2 賠率2
 * @param	strChoiceNumber 所選擇號碼
 * @param	CheckKey1 檢查值1
 * @param	CheckKey2 檢查值2
 * @return	 Array
 */
	function RealSuppleWager($intLID, $intLType, $intGID, $intBT, $strNum, $intStake, $strOID, $flOdds, $strOID2, $flOdds2, $strChoiceNumber, $CheckKey1,  $CheckKey2){
		global $_KSysParam, $_intLang;

		if( $_KSysParam[RealSuppleWagerIP] == ""){
			$strHttpHost = $_SERVER["HTTP_HOST"];
		}else{
			$strHttpHost = $_KSysParam[RealSuppleWagerIP];
		}

		if($intLType == 1 && $intBT >= 7 && $intBT <= 11){
			$strNum = str_replace(",", "|", $strNum);
			if(!empty($strOID2))$strOID .= "|".$strOID2;
			if(!empty($flOdds2))$flOdds .= "|".$flOdds2;

			$strLink = "http://".$strHttpHost."/member/login_supple.php?userid=".$_SESSION["Admin_Info"] -> ID."&lang=".$_intLang."&Account=".$_SESSION["Admin_Info"] -> Account."&LottoID=".$intLID."&Bet_Type=".$intBT."&JoinNumber=".$strNum."&OddsID=".$strOID."&Odds=".$flOdds."&StakeMoney=".$intStake."&CheckKey1=".$CheckKey1."&CheckKey2=".$CheckKey2."&GambleID=".$intGID;
		}elseif($intLType == 1 && $intBT >= 31 && $intBT <= 43){
			$strLink = "http://".$strHttpHost."/member/login_supple.php?userid=".$_SESSION["Admin_Info"] -> ID."&lang=".$_intLang."&Account=".$_SESSION["Admin_Info"] -> Account."&LottoID=".$intLID."&Bet_Type=".$intBT."&Number=".$strNum."&JoinNumber=".$strChoiceNumber."&OddsID=".$strOID."&Odds=".$flOdds."&StakeMoney=".$intStake."&CheckKey1=".$CheckKey1."&CheckKey2=".$CheckKey2."&GambleID=".$intGID;
		}else{
			$strLink = "http://".$strHttpHost."/member/login_supple.php?userid=".$_SESSION["Admin_Info"] -> ID."&lang=".$_intLang."&Account=".$_SESSION["Admin_Info"] -> Account."&LottoID=".$intLID."&Bet_Type=".$intBT."&Number=".$strNum."&OddsID=".$strOID."&Odds=".$flOdds."&StakeMoney=".$intStake."&CheckKey1=".$CheckKey1."&CheckKey2=".$CheckKey2."&GambleID=".$intGID."&ChoiceNumber=".$strChoiceNumber;
		}
		//print "<!--".$strLink."//-->Q";

		$intT = time();
		$ch = curl_init ();
		curl_setopt($ch,CURLOPT_URL, $strLink);
		//curl_setopt ($ch, CURLOPT_VERBOSE, 0);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt ($ch, CURLOPT_HEADER, 0);
		curl_setopt ($ch, CURLOPT_HTTPHEADER, array(
			"Accept:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/x-shockwave-flash, */*",
			"User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)",
			"Host:".$_SERVER["HTTP_HOST"],
			"Connection:Keep-Alive"));
		$strCon = curl_exec ($ch);
		curl_close ($ch);
		print $strCon."\n\n";
		//exit($strLink);
		//$strCon = join("", file($strLink));
		if(preg_match("/No Power/i", $strCon))print $strCon;
		//print (time() - $intT);
		$arrResult["isWager"] = false;
		if($_SESSION["DEBUG"])print $strCon;

		if(trim($strCon) == ""){
			$arrResult["WagerCon"] = "Wager Error!!";
		}elseif(preg_match("/Succ Tip/", $strCon)){
			preg_match("/<!--Succ Tip\/\/-->(.+)<!--Succ Tip\/\/-->/s", $strCon, $arrCon);
			$arrResult["WagerTip"] = $arrCon[1];
			preg_match("/<!--Succ Con\/\/-->(.+)<!--Succ Con\/\/-->/s", $strCon, $arrCon);
			$arrResult["WagerCon"] = $arrCon[1];
			$arrResult["isWager"] = true;
		}else{
			preg_match("/<!--Err Con\/\/-->(.+)<!--Err Con\/\/-->/", $strCon, $arrCon);
			$arrResult["WagerCon"] = $arrCon[1];
			//print $arrResult["WagerCon"]."aaaa";
		}
		//print($arrResult["WagerCon"]);
		return $arrResult;
	}


/**
 * 檢驗是否超過上層信用額度
 * @param	intMemStake 會員此次下注金額
 * @param	intSubID 代理商序號
 * @param	intSubCredit 代理商信用額度
 * @param	intMainID 總代理序號
 * @param	intMainCredit 總代理信用額度
 * @return	錯誤時傳回false 程式終止，正確傳回 true
 */
	function isOverParentCredit($intMemStake, $intSubID, $intSubCredit, $intMainID, $intMainCredit){
		return false;
		global $_Conn, $$_Conn;
		//檢驗代理商信用總額
		$strSQL = "select sum(MemStake*MemExchangeRate) as MemStake from `bet_BetListTmp` where SubID = '".(int)$intSubID."' and PayupDate >= Current_Date() and isPayOff >= 0 and WagerType = 0";
		if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)) {
			$GLOBALS["errormessage"] = "Find User Wager Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nLine:".__LINE__."\nPage:".__FILE__;
			return true;
		}
		if(PMA_mysql_num_rows($RS) > 0){
			$Rows = PMA_mysql_fetch_object($RS);
			if($Rows -> MemStake + $intMemStake > $intSubCredit){
				print "<!--SW:".$Rows -> MemStake.", W:".$intMemStake.", MC:".$intSubCredit."//-->";
				return true;
			}
		}
		//檢驗總代理信用總額
		$strSQL = "select sum(MemStake*MemExchangeRate) as MemStake from `bet_BetListTmp` where MainID = '".(int)$intMainID."' and PayupDate >= Current_Date() and isPayOff >= 0 and WagerType = 0";
		if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)) {
			$GLOBALS["errormessage"] = "Find User Wager Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nLine:".__LINE__."\nPage:".__FILE__;
			return true;
		}
		if(PMA_mysql_num_rows($RS) > 0){
			$Rows = PMA_mysql_fetch_object($RS);
			if($Rows -> MemStake + $intMemStake > $intMainCredit){
				print "<!--SW:".$Rows -> MemStake.", W:".$intMemStake.", MC:".$intMainCredit."//-->";
				return true;
			}
		}
		return false;
	}


/**
 * 設定注單排隊
 * @param	intWageID 注單序號
 * @return	錯誤時傳回false 程式終止，正確傳回 true
 */
	function setWagerOrder($intWageID, $intUserID){
		global $_ConnMaster;
		$strSQL = "insert into `bet_BetControl`(`BetKey`, `BetTime`, `UserID`) values('CS-".(string)$intWageID."', UNIX_TIMESTAMP(), '".$intUserID."')";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)) {
			$GLOBALS["errormessage"] = "Add Control Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		return true;
	}

/**
 * 宜除注單排隊
 * @param	intWageID 注單序號
 * @return	錯誤時傳回false 程式終止，正確傳回 true
 */
	function rmWagerOrder($intWageID){
		global $_ConnMaster;
		$strSQL = "delete from `bet_BetControl` where `BetKey` = 'CS-".(string)$intWageID."'";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)) {
			$GLOBALS["errormessage"] = "Remove Control Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		return true;
	}

/**
 * 取得注單排隊序號
 * @param	intWageID 注單序號
 * @return	錯誤時傳回false 程式終止，正確傳回 true
 */
	function getWagerOrder($intWageID){
		global $_ConnMaster;
		$strSQL = "select `BetKey` from `bet_BetControl` where `BetKey` = 'CS-".(string)$intWageID."' limit 0,1";
		if(!$RS = @PMA_mysql_query($strSQL, $_ConnMaster)) {
			$GLOBALS["errormessage"] = "Find Control Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		if(PMA_mysql_num_rows($RS) == 0)return 0;
		$Rows = PMA_mysql_fetch_object($RS);
		$strBetKey = str_replace("CS-", "", $Rows -> BetKey);
		return ((int)$strBetKey);
	}


/**
 * 找出該使用者上層實際已接收注額
 * @param	intLID 使用者序號陣列
 * @param	intGID 使用者序號陣列
 * @param	arrBT 使用者序號陣列
 * @param	arrNum 使用者序號陣列
 * @param	arrUID 使用者序號陣列
 * @return	成功傳回 Array
 */
	function getUserUpLayerRealStake($intLID, $intGID, $arrBT, $arrNum, $arrUID){
		global $_Conn, $$_Conn;
		$arrCon = array();
		if(!is_array($arrUID))return $arrCon;
		if(sizeof($arrUID) == 0)return $arrCon;

		$strSQL = "select UserID, Bet_Type, Number, (tolRealStake - tolSuppleStake) as tolStake from `bet_RealTodayGame".$intLID."` where LottoID = ".$intLID." and GambleID = ".$intGID." and UserID in (".implode(",", $arrUID).")";
		if(sizeof($arrBT) > 0){
			if($intLID == 1 && in_array(28, $arrBT)) $arrBT[] = 1;  //若有特碼B，就多要抓特碼 A
			elseif($intLID == 1 && in_array(1, $arrBT)) $arrBT[] = 28;  //若有特碼A，就多要抓特碼 B
			$strSQL .= " and Bet_Type in (".implode(",", $arrBT).")";
		}
		if(sizeof($arrNum) > 0)$strSQL .= " and Number in (".implode(",", $arrNum).")";
		if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
			$GLOBALS["errormessage"] = "Find Member Data Error!!";
			$GLOBALS["errorhidden"] = "\n Error: ".PMA_mysql_error($$_Conn).",\nSQL: ".$strSQL.",\nLine: ".__LINE__.",\nPage: ".__FILE__;
			return false;
		}
		if(PMA_mysql_num_rows($RS) == 0)return $arrCon;
		while($Rows = PMA_mysql_fetch_object($RS)){
			$arrCon[$Rows -> Bet_Type][$Rows -> Number][$Rows -> UserID] += $Rows -> tolStake;
			if($intLID == 1){
				if($Rows -> Bet_Type == 1)$arrCon[28][$Rows -> Number][$Rows -> UserID] += $Rows -> tolStake;
				if($Rows -> Bet_Type == 28)$arrCon[1][$Rows -> Number][$Rows -> UserID] += $Rows -> tolStake;
			}
		}
		//if($intLID == 1 && in_array(28, $arrBT))$arrCon[28] = $arrCon[1];
		return $arrCon;
	}
//-------------------------------------------------------//
//Wager_lib End
}
?>